package com.ice.body.dict.controller;
import com.ice.body.dict.model.SwitchModel;
import com.ice.body.dict.service.SwitchService;
import io.swagger.annotations.ApiOperation;
import com.ice.base.controller.BaseController;
import com.github.pagehelper.PageHelper;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.ice.base.result.ResponseResult;
import com.ice.base.result.AjaxResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2021-07-09
 * Time: 11:27
 */
@RestController
@ApiIgnore(value = "配置开关-配置开关")
public class SwitchController extends BaseController{
    //---------------------------配置开关-配置开关-----------------------start
    @Resource
    private SwitchService switchService;
    
    @ApiOperation(value = "配置开关-配置开关-新增")
    @PostMapping("/api/Switch/insert")
    public AjaxResult<SwitchModel> insert_Switch(SwitchModel model) {
        AjaxResult r = ResponseResult.success();
        try{
            switchService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiIgnore(value = "配置开关-配置开关-删除")
    @PostMapping("/api/Switch/deleteById")
    public AjaxResult<SwitchModel> deleteById_Switch(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
            switchService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "配置开关-配置开关-更新")
    @PostMapping("/api/Switch/updateById")
    public AjaxResult<SwitchModel> update_Switch(SwitchModel model) {
        AjaxResult r = ResponseResult.success();
        try{
             switchService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiIgnore(value = "配置开关-配置开关-查询一个")
    @PostMapping("/api/Switch/selectById")
    public AjaxResult<SwitchModel> selectById_Switch(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           SwitchModel model = switchService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiIgnore(value = "配置开关-配置开关-查询多个")
    @PostMapping("/api/Switch/selectAll")
    public AjaxResult<SwitchModel> selectList_Switch(SwitchModel model) {
        AjaxResult r = ResponseResult.success();
        try{
           List<SwitchModel> list = switchService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiIgnore(value = "配置开关-配置开关-查询分页")
    @PostMapping("/api/Switch/selectListByPageHelper")
    public AjaxResult<SwitchModel> selectListByPageHelper_Switch(@RequestParam(name = "pageSize") Integer pageSize,
                                                                 @RequestParam(name = "pageNum") Integer pageNum,
                                                                 SwitchModel model){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
           list = switchService.selectListByModel(model);
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------配置开关-配置开关-----------------------end

}
